<template>
  <div class="tenant-container">
    <!-- 用户名称搜索  状态搜索 -->
    <ContentWrap>
      <el-form ref="queryFormRef" class="-mb-15px" :model="queryParams" :inline="true" label-width="68px">
        <el-form-item label="会员ID" prop="id">
          <el-input v-model="queryParams.id" placeholder="请输入会员ID" class="!w-240px" />
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="queryParams.mobile" placeholder="请输入手机号" class="!w-240px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">查询</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </ContentWrap>
    <!-- 记录列表 -->
    <ContentWrap>
      <el-table :data="tableData" :stripe="true" :show-overflow-tooltip="true" :loading="loading">
        <el-table-column label="会员Id" prop="id" align="center" />
        <el-table-column label="会员" prop="mobile" align="center" />
        <el-table-column label="计费方式" prop="purchaseType" align="center">
          <template #default="scope">
            <dict-tag :type="DICT_TYPE.TONGUE_BILLING_METHOD" :value="scope.row.purchaseType" />
          </template>
        </el-table-column>
        <el-table-column label="免费剩余次数" prop="remainFreeTimes" align="center" />
        <el-table-column label="剩余次数" prop="remainAllTimes" align="center" />
        <el-table-column label="使用次数" prop="usedTimes" align="center" />
        <el-table-column label="最高得分" prop="tongueTopScore" align="center" />
        <el-table-column
label="到期时间" align="center" prop="chargeTongueExpired" :formatter="dateFormatter"
          width="180" />
        <el-table-column label="操作" align="center" width="150px">
          <template #default="scope">
            <el-button type="primary" link @click="handleView(scope.row)">添加</el-button>
            <el-button type="primary" link @click="handleSee(scope.row)">查看记录</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
:total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
        @pagination="getList" />
      <AddNum ref="AddNumRef" @success="getList" />
      <SeeRecord ref="SeeRecordRef"/>
    </ContentWrap>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs } from 'vue'
import { dateFormatter } from '@/utils/formatTime'
import { DICT_TYPE } from '@/utils/dict'
import SeeRecord from './seeRecord.vue'
import { TongueMemberApi } from '@/api/application/tongue/member'
import AddNum from './addNum.vue'
const state = reactive({
  queryParams: {
    id: '',
    mobile: '',
    pageNo: 1,
    pageSize: 10
  },
  loading: false,
  tableData: [],
  total: 0,
  seeRecordVisible: false,
  editType: 'add',
  editData: {}
})
const { queryParams, loading, tableData, total, seeRecordVisible, editType, editData } = toRefs(state)
const queryFormRef = ref() // 搜索的表单
const AddNumRef = ref()
const SeeRecordRef = ref()
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await TongueMemberApi.getMemberPage(queryParams.value)
    tableData.value = data.list
    total.value = data.total
    // console.log(data)
    // console.log(tableData.value)
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  getList()
}

/** 重置按钮操作 */
const handleReset = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}
onMounted(() => {
  getList()
})
const handleView = (row?: any) => {
  AddNumRef.value.open(row)
}
const handleSee = (row?: any) => {
  SeeRecordRef.value.open(row)
}

</script>

<style scoped lang="scss"></style>